<template>
	<view>
		 <uni-card  v-for="(item,index) in list" >	
						  <p style="float: right; color: #007AFF;" @click="details(item.contractId)">合同详情</p>
			 <text>合同编号：{{item.contractId}}
			       签订人：{{item.applyName}}
				   合同金额：{{item.contractMoney}}
			       有效期：{{item.effectiveTime}} -- {{item.failureTime}}
				   合同状态：{{item.contractState==0 ?"待确认"
				             :item.contractState==1?"待签定"
							 :item.contractState==2?"待付款":"已生效"}}
			</text>
			
			<button 
			v-if="item.contractState==1"
			@click="compile(item.contractId,2)">签订</button>
			<button
			class="btn"
			v-if="item.contractState==2"
			@click="payment(item.contractId)">付款</button>
		</uni-card>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				stuId:"",				
				list:{},
				pdfUrl:'',
				htmlurl:'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-63531941-e4e0-492f-9af4-3fafca12aa68/bb7dbbe8-c1da-450b-be23-73d8e8ae8957.jpg',
				extraIcon:{
					size: '22',
					type: 'gear-filled'
			    }
				
			}
		},
		methods:{
			compiles(){
				uni.redirectTo({
					url: '/pages/user/setup/success',
				});
			},
			getinfo(){
				/* alert(contractState) */
				this.$axios.get("/applycontract/applyContract/lists?stuId="+this.stuId).then((res)=>{
					this.list = res.data.result;
				})
			},
			details(contractId){
				uni.redirectTo({
					url: '/pages/user/setup/xiangqing',
				});
			},
			//付款
			payment(contractId){
				this.$axios.get("/applycontract/applyContract/pay?contractId="+contractId).then((res)=>{
					document.write(res.data.message)
				})
				
			},
			compile(contractId,newContractState){
				this.$axios.get("/applycontract/applyContract/upstatus?contractId="+contractId+
				                 '&contractState='+newContractState).then((res)=>{
								if(res.data.success){
									uni.showToast({
											icon: 'success',
											position: 'bottom',
											title: '签订成功！'
										});
									}
									this.getinfo();
								 })
			}
		},
		created() {
			 this.getinfo();
		},
		onLoad: function (option) { //option为object类型，会序列化上个页面传递的参数
			this.stuId = option.stuId;//学生编号
		}
	}
</script>

<style lang="less">
	.btn{
		width: 20%;
		text-align: center; 
		float: right;
		margin-bottom: 15px;
		font-size: 15px;
	}
</style>
